package collection;

import java.util.HashSet;
import java.util.Set;

public class SetDemo {
    public static void main(String[] args) {
        // build
        Set<Integer> set = new HashSet<Integer>();
        System.out.println(set.isEmpty());
        set.add(1);
        set.addAll(new HashSet<Integer>() {
            {
                add(2);
                add(3);
            }
        });
        System.out.println(set.isEmpty());
        System.out.println(set.size());
        // browse
        System.out.println(set);
        // search
        Integer value = 1;
        if (set.contains(value)) {
            set.remove(value);
            System.out.println(set.contains(value));
            System.out.println(set.size());
        }
        // compare
        Set<Integer> set2 = new HashSet<Integer>();
        set2.addAll(set);
        System.out.println(set.equals(set2));
        set.clear();
        System.out.println(set.isEmpty());
        System.out.println(set.equals(set2));
        // iterate
        set2.forEach(item -> System.out.println(item));
    }
}
